<?php
// +----------------------------------------------------------------------
// | makePHP 
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://makephp.org All rights reserved.
// +----------------------------------------------------------------------
// | Licensed BSD.(http://www.make.org/BSD-license.txt)
// +----------------------------------------------------------------------
// | Author: 叁石(sanshi) <sanshi0815@tom.com>
// | Author: 白家昌<baijc2004cn@126.com>
// +----------------------------------------------------------------------
/**
 *  Entrance File of the Control class.
 *
 * @Author:    Mirze<mirze@foxmail.com>
 * @Package:   Interface of the View class. 
 * @Version:   $Id: zy_week_report.class.php 2011-12-06 15:59:17 $
 * @Show Note: 作业周报
 */
Class export_data extends TheAdmin
{
	/* DataBase object */
	public $db;

	/* View the data page limit items */
	public $pageSize = 10;
	
	/**
	 *	Construct this module class.
	*/
	public function export_data()
	{
	}
	public function set()
	{
		$this->TheAdmin();
		//定义模版
		$this->tplFile ="export_data.tpl";
		$this->admin_user_id = $this->userRequest->get('admin_user_id');
		//取得数据库连接
		//$this->db = Factory::getDB("export_data");
		//取得用户对于该类的权限
		$user_p = $this->get_user_popedom_by_class_name(__CLASS__);
		$class_p_arr = $this->show_p();
		//取得该类的权值数组
		$class_method = $class_p_arr['class_method'];
		//取得用户操作菜单
		$menu = array();
		foreach ($class_method as $k=>$v)
		{
			if( (parse_power($user_p,$v[2]) && (isset($v[3]) ?$v[3] :false)) || IS_ROOT)
			{
				array_push($menu,array('url'=>"?c=".__CLASS__."&m={$v[0]}",'title'=>$v[1]));
			}
		}
		//用户有权菜单生成 可以添加其他操作
		$this->smarty->assign('menus',$menu);
		$this->smarty->assign("main_menus",$this->get_user_menus());
	}
	
	/**
	 *	Call class construct method.
	*/
	public function __construct()
	{
			$this->export_data();
	}
	public function _display()
	{
		$this->smarty->display($this->tplFile);
	}
	/**
	 *	default method.
	*/
	public function show()
	{
		$this->smarty->assign('act','list');
		$this->smarty->display($this->tplFile);
	}
	
	/**
	 *	add method.
	*/
	public function add()
	{		
		$this->smarty->assign('act','add');
		$this->smarty->display($this->tplFile);
	}
	
	/**
	 *	edit method.
	*/
	public function edit()
	{
		//取得id，也就是唯一索引
		$active_id = isset($_REQUEST['active_id']) ? intval(trim($_REQUEST['active_id'])) : 0 ;
		//取得是否查看详情
		$is_show = isset($_REQUEST['is_show']) ? intval(trim($_REQUEST['is_show'])) : 0 ;
		if(!isset($_REQUEST['post']) || trim($_REQUEST['post'])!=1)
		{
			//使用模版，展示提交界面
			$result = $this->db->getOne($active_id);
			if(empty($result))
			{
				alertMsg('-2001', 'index.php?c=export_data');
			}
			foreach ($result AS $k=>$v)
			{
				$this->smarty->assign("{$k}",$v);
			}
			$this->smarty->assign('is_show',$is_show);
			$this->smarty->assign('act_title','修改');
			$this->smarty->assign('act','edit');
			$this->smarty->display($this->tplFile);
		} else {
			//用户提交，把数据插入数据库
			//设置where条件
			$where = "active_id=$active_id";
			$temp = $this->getValue(1);
			$update = $this->db->update_export_data($temp,$where);
			admin_log($this->admin_user_id,__METHOD__,$where,2);
			$error_no = 0 > $update ?  $update :'-1502';
			//取得错误的sql语句
			//$error_sql = end($this->db->getDebugMsg());
			//echo $error_sql;
			alertMsg($error_no, 'index.php?c=export_data');
		}
	}
	
	/**
	 *	browse method.
	*/
	public function browse() {
		$active_id = isset($_REQUEST['active_id']) ? intval(trim($_REQUEST['active_id'])) : 0 ;
		//使用模版，展示提交界面
		$result = $this->db->getOne($active_id);
		if(empty($result))
		{
			alertMsg('-2001', 'index.php?c=export_data');
		}
		foreach ($result AS $k=>$v)
		{
			$this->smarty->assign("{$k}",$v);
		}
		//$this->smarty->assign('is_show',$is_show);
		$this->smarty->assign('act_title','查看');
		$this->smarty->assign('act','browse');
		$this->smarty->display($this->tplFile);
	}
	
	/**
	 *	del method.
	*/
	public function del()
	{
		//取得id，也就是唯一索引
		$active_id = isset($_REQUEST['active_id']) ? intval(trim($_REQUEST['active_id'])) : 0 ;
		$where = "active_id=$active_id";
		$del=$this->db->delete_export_data($where);
		admin_log($this->admin_user_id,__METHOD__,$where,3);
		$error_no = 0 > $del ?  $del :'-1503';
		//取得错误的sql语句
		//$error_sql = end($this->db->getDebugMsg());
		//echo $error_sql;
		alertMsg($error_no, 'index.php?c=export_data');
	}
	
	/**
	 *	get request method.
	*/
	public function &getValue($isEdit=0)
	{
		$temp = array();
		$check = Factory::getBaseClass("checkBase");
		if($isEdit){
			$temp['active_id'] = $_POST['active_id'];
		} else {
			$temp['active_id'] = "";
		}
		//补充其他的字段
				$temp['team_name'] = $_POST['team_name'];
				$temp['well_name'] = $_POST['well_name'];
				$temp['work_type'] = $_POST['work_type'];
				$temp['well_ptd'] = $_POST['well_ptd'];
				$temp['ctd'] = $_POST['ctd'];
				$temp['work_plan'] = $_POST['work_plan'];
				$temp['next_well'] = $_POST['next_well'];
				$temp['active_info'] = $_POST['active_info'];
				$temp['create_time'] = $_POST['create_time'];
				$temp['week_time'] = $_POST['week_time'];
				$temp['project'] = $_POST['project'];
				$temp['create_user'] = $_POST['create_user'];
				$temp['department'] = $_POST['department'];
				
		admin_log($this->admin_user_id,__METHOD__,serialize($temp),2);	
		return $temp;
	}
	/**
	 *	get class method and popedom.
	*/
	public function show_p()
	{
		//该方法为，提供用户使用方法定义，非web用户权限相关不用写
		return array(
			/* 定义该类中文名称*/
			'class_name'=>array(__CLASS__,'作业周报'),
			'class_method' =>array(
				//array（方法名，中文解释，权值,是否为菜单）
				'show'  => array('show','列表',1,true),
				'add'  => array('add','添加',2,true),
				'edit'  => array('edit','编辑',4,false),
				'del'  => array('del','删除',8,false),
				'browse' => array('browse', '查看', 16, false),
				'show_p'=> array('show_p','',0,false)
			)
		);
	}
}

?>